#define _CRT_SECURE_NO_WARNINGS 1

#include <algorithm>
#include <iostream>
#include <stack>
#include <vector>
using namespace std;

typedef pair<int, int> PII;

int main()
{
    int n;
    cin >> n;
    vector<PII> num;
    for (int i = 0; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        num.push_back({ a,b });
    }
    sort(num.begin(), num.end());

    stack<PII> s;
    for (int i = 0; i < n; i++)
    {
        while (s.size() && s.top().second < num[i].second)
            s.pop();

        s.push(num[i]);
    }

    vector<PII> res;
    while (s.size())
    {
        res.push_back(s.top());
        s.pop();
    }

    for (int i = res.size() - 1; i >= 0; i--)
        cout << res[i].first << " " << res[i].second << endl;
    return 0;
}